package com.kly.smartbi.model.enums;

import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Getter
public enum QuestionSubmitLanguageEnum {
    JAVA(0, "Java"),
    C_PLUS_PLUS(1, "C++"),
    PYTHON(2, "Python"),
    JAVASCRIPT(3, "JavaScript"),
    C_SHARP(4, "C#"),
    GO(5, "Go");

    // 私有final属性确保不可变性
    private final int value;
    private final String text;

    // 私有构造函数强制通过枚举常量实例化
    QuestionSubmitLanguageEnum(int value, String text) {
        this.value = value;
        this.text = text;
    }

    // 获取枚举值列表
    private static List<String> getValues() {
        return Stream.of(values()).map(QuestionSubmitLanguageEnum::getText).collect(Collectors.toList());
    }

    // 通过value反向获取枚举实例
    public static QuestionSubmitLanguageEnum fromValue(String value) {
        for (QuestionSubmitLanguageEnum language : values()) {
            if (language.getText().equals(value)) return language;
        }
        return null;
    }
}